/**
 * creation: 11-apr-2006
 */
package org.jfonia.rhythm;

import org.jfonia.util.JFoniaException;

/**
 * 
 * 
 * @author Wijnand
 *
 */
public class CDuration
{
    /**
     * value constants
     */
	public static final int LONG        = -2;
	public static final int BREVE        = -1;
	public static final int WHOLE        = 0;
    public static final int HALF         = 1;
    public static final int QUARTER      = 2;
    public static final int EIGHT        = 3;
    public static final int SIXTEENTH    = 4;
    public static final int THIRTYSECOND = 5;
    public static final int SIXTYFOURTH  = 6;
   
    public static final int RECIP[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024};
    
    /**
	 * @param value 0:whole, 1:half, 2:quarter, 3:eight etc.
	 * @param dotCount number of augmentation dots
     * @throws JFoniaException if value is not supported
	 */
	public CDuration(int value, int dotCount) throws JFoniaException 
	{
    	if (value < 0)
    		throw new JFoniaException("reciproque not defined");
    	else if (value >= RECIP.length)
    		throw new JFoniaException("value too large");
		this.value = value;
		this.dotCount = dotCount;
	}

	public int getValue()
    {
        return value;
    }
    
    public void setValue(int v)
    {
    	value = v;
    }
    
    /**
     * get the number of augmentation dots (which extend the duration by a factor 3/2 each) 
     */
    public int getDotCount()
    {
        return dotCount;
    }
    
    /**
     * @return reciprocal duration : 1=whole, 2=half, 4=quarter, etc.
     * @throws JFoniaException 
     */
    public int getRecip()
    {
    	return RECIP[value];
    }
    
	protected int        value;
	protected int        dotCount;
	
}
